<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var combinationSum = function (candidates, target) {
        let res = []
        function backTracking(path, start, sum) {
          if (sum > target) return
          if (sum == target) {
            return res.push([...path])
          }
          for (let i = start; i < candidates.length; i++) {
            path.push(candidates[i])
            backTracking(path, i, sum + candidates[i])
            path.pop()
          }
        }
        backTracking([], 0, 0)
        return res
      }
    </script>
  </body>
</html>
